import dt from '@dt/dt'
import ruleMgr from '@/biz/option/rule.js'
import paramsMgr from '@/biz/bonus/params.js'

function value(_this) {
  let way = _this.info.defaultChannelSomeWay
  let input = {
        type: 'number',
        min: 0
      }
      
  if (way == '1') {
    input.max = 100
  }
  return [{
    key: 'defaultChannelSomeWayValue',
    col: 9,
    placeholder: way == '1' ? '请输入折算比例' : way == '2' ? '请输入固定提点' : '请输入固定金额',
    input
  }, {
    placeholder: way == '1' ? '%' : way == '2' ? '万分之' : '元',
    col: 6,
    text: {}
  }]
}

function options(_this) {
  function group() {
    return [
      {
        key: 'defaultChannelSomeWay',
        col: 9,
        select: {
          key: 'mentionSomethingType'
        },
        change: () => {
          opt[0][0].group = group()
        }
      },
      ...value(_this)
    ]
  }
  
  let opt = [
    [{
      key: 'defaultChannelSomeWayValue',
      title: '默认渠道成交提点',
      col: 12,
      group: group()
    }, {
      col: 3,
      button: {
        title: '新增渠道设置',
        type: 'primary',
        ghost: true,
        click: () => {
          _this.list.push({
            postIds: [],
            productIds: [],
            channel: [],
            someWay: '1',
            someWayValue: 100
          })
        }
      }
    }]
  ]
  return opt
}

function columns(_this, flag) {
  return [{
      type: 'index',
      title: '序号',
      width: 60
    },
    {
      title: '岗位',
      minWidth: 180,
      cell: (row) => {
        return {
          edit: {
            key: 'postIds',
            placeholder: '请选择岗位(多选)',
            select: {
              options: paramsMgr.positions(_this.list, row, false),
              multiple: true,
              maxTagCount: 1
            }
          }
        }
      }
    },
    {
      title: '产品',
      minWidth: 180,
      cell: (row) => {
        return {
          edit: {
            key: 'productIds',
            placeholder: '请选择产品(多选)',
            select: {
              options: paramsMgr.products(_this.list, row, false),
              multiple: true,
              maxTagCount: 1
            }
          }
        }
      }
    },
    {
      title: '渠道',
      minWidth: 180,
      cell: (row) => {
        return {
          edit: {
            key: 'channel',
            placeholder: '请选择渠道(多选)',
            select: {
              options: paramsMgr.channels(),
              multiple: true,
              maxTagCount: 1
            }
          }
        }
      }
    },
    {
      title: '提点',
      width: 280,
      cell: (row) => {
        let input = {
          type: 'number',
          min: 0
        }
        if (row.someWay == '1') {
          input.max = 100
        }
        return {
          group: [{
            key: 'someWay',
            col: 10,
            select: {
              key: 'mentionSomethingType'
            }
          }, {
            key: 'someWayValue',
            col: 9,
            placeholder: row.someWay == '1' ? '请输入折算比例' : row.someWay == '2' ? '请输入固定提点' : '请输入固定金额',
            input
          }, {
            placeholder: row.someWay == '1' ? '%' : row.someWay == '2' ? '万分之' : '元',
            col: 5,
            text: {}
          }]
        }
      }
    },
    {
      field: 'handles',
      title: '操作',
      width: 70,
      cell: (row) => {
        return {
          btn: [{
            title: '删除',
            event: 'onDelete',
          }]
        }
      }
    }
  ]
}

function helps() {
  return [{
      label: '渠道成交奖金设置',
      value: ['若项目下不同渠道奖金发放规则不同，请优先配置“渠道成交奖金设置”']
    }, {
      label: '默认渠道成交提点',
      value: [
        '配置后，所有岗位所有产品所有一级渠道为“渠道带看”类别下的房源按此配置计算',
        '设置为“折算比例”，则结算奖金=当前结算奖金*折算比例%',
        '设置为“固定提点”，则结算奖金=本次结算总销*固定提点，注：设置为固定提点后，发放标准、职级点数、职级跳点不再适用',
        '设置为“固定金额”，则结算奖金=该固定金额，注：设置为固定金额后，发放标准、职级点数、职级跳点不再适用'
      ]
    }, {
      label: '新增渠道设置',
      value: ['可选择不同岗位、不同产品、不同渠道设置不同的提点，未设置的情况按默认渠道成交提点计算']
    }, {
      tips: '以上配置在保存后即时生效，不影响已发起奖金单',
    },
  ]
}

export default {
  options,
  columns,
  helps
}
